#!/usr/bin/perl

print "#Table of Contents\n";

while(<>) {
   chop;
   if(/^(#+)\s*(\S.*)/) {
      my($n) = length($1)-1;     # -- right now ## is minimum, if you have a # only, remove '-1'
      my($t) = $2;
      for(my $i=0; $i<$n; $i++) {
         print " ";
      }
      
      # Web Browser & Command-Line Interface aka "Dual Use"
      # web-browser--command-line-interface-aka-dual-use
      $t =~ s/\s*$//;
      my($l) = lc($t);
      $l =~ s/[^\w -]//g;
      $l =~ s/ /-/g;
      print "* [$t](User-Guide#$l)\n";
   }
}
